package axdoc.done;

import java.util.ArrayList;
import java.util.List;

import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import com.redis.JedisService;

import axdoc.rule.MessageHandleFacotry;

public class ThreadManager {

	List<ThreadRunnable> threads = new ArrayList<ThreadRunnable>();

	ThreadPoolTaskExecutor taskExecutor;

	JedisService jedisService;

	MessageHandleFacotry messageHandleFacotry;

	public ThreadPoolTaskExecutor getTaskExecutor() {
		return taskExecutor;
	}

	public void setTaskExecutor(ThreadPoolTaskExecutor taskExecutor) {
		this.taskExecutor = taskExecutor;
	}

	public JedisService getJedisService() {
		return jedisService;
	}

	public void setJedisService(JedisService jedisService) {
		this.jedisService = jedisService;
	}

	public MessageHandleFacotry getMessageHandleFacotry() {
		return messageHandleFacotry;
	}

	public void setMessageHandleFacotry(MessageHandleFacotry messageHandleFacotry) {
		this.messageHandleFacotry = messageHandleFacotry;
	}

	public void init() {
		for (int i = 0; i < 1; i++) {
			ThreadRunnable thread = new ThreadRunnable(jedisService, messageHandleFacotry);
			taskExecutor.execute(thread);
			threads.add(thread);
		}
	}

	public int getActiveCount() {
		return taskExecutor.getActiveCount();
	}

	public int getPoolSize() {
		return taskExecutor.getPoolSize();
	}

	public int getMaxPoolSize() {
		return taskExecutor.getMaxPoolSize();
	}

	public int getCorePoolSize() {
		return taskExecutor.getCorePoolSize();
	}

	public void addThread() {
		ThreadRunnable thread = new ThreadRunnable(jedisService, messageHandleFacotry);
		taskExecutor.execute(thread);
		threads.add(thread);
	}

	public void removeThread() {
		taskExecutor.getThreadPoolExecutor().getQueue().remove();
	}

}
